<template>
  <div>
    <h2>随机点名</h2>
    <div class="box">
      <span>名字是：</span>
      <div class="qs">{{edit}}</div>
    </div>
    <div class="btns">
      <button @click="start" :disabled= "disabled"  class="start">开始</button>
      <button @click="end"  :disabled= "disabled" class="end">结束</button>
    </div>
  </div>
</template>

<script>

export default {
  data(){
    return{
      edit:'这里显示姓名',
      arr:["马超","诸葛亮","刘备","赵云","关羽","黄忠"],
      random:'',
      times:'',
      disabled:false,
      

      

    }
  },
  methods:{
    start(){
      if(this.arr.length===1){
        this.disabled=true
       alert("最后一个学员了")      }
      
     this.times=setInterval(()=>{
       this.edit=this.arr[parseInt(Math.random()*this.arr.length)]
     },10)
    },
    end(){
      clearInterval(this.times)
      this.random=parseInt(Math.random()*this.arr.length)
      this.edit=this.arr[this.random]
      this.arr.splice(this.random, 1);
    }
  }
  
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
}

.box {
  width: 600px;
  margin: 50px auto;
  display: flex;
  font-size: 25px;
  line-height: 40px;
}

.qs {
  width: 450px;
  height: 40px;
  color: red;
}

.btns {
  text-align: center;
}

.btns button {
  width: 120px;
  height: 35px;
  margin: 0 50px;
}
</style>